home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / C⁄C++ / mgraph / pendulum.c < prev    next >
C/C++ Source or Header  |  1994-03-22  |  1KB  |  74 lines

  1. /* Copyright 1994 Ralph Gonzalez */
  2.  
  3. /*
  4. *    FILE:        pendulum.c
  5. *    AUTHOR:        R. Gonzalez
  6. *    CREATED:    Nov. 20, 1991
  7. *    MODIFIED:    March 15, 1994 to agree with new mgraph version
  8. *
  9. *    Sample application using mgraph/xgraph library.
  10. *
  11. *    PROJECT CONTENTS:
  12. *        pendulum.c/.cc, mgraph.c/xgraph.cc
  13. */
  14.  
  15. # ifdef THINK_C
  16. # include "mgraph.h"
  17. # else
  18. # include "xgraph.h"
  19. # endif
  20. # include <stdio.h>
  21. # include <math.h>
  22.  
  23. # define CENTER_X    0.
  24. # define CENTER_Y    0.
  25. # define RADIUS1    .7
  26. # define RADIUS2    .2
  27. # ifndef PI
  28. # define PI            3.1415926
  29. # endif
  30.  
  31. main()
  32. {
  33.     double    x,
  34.             y,
  35.             old_x,
  36.             old_y,
  37.             angle = 0.,
  38.             increment,
  39.             mouse_x,
  40.             mouse_y;
  41.  
  42.     init_graphics();    /* Don't forget to do this FIRST! */
  43.     
  44.     printf("Move mouse vertically to change speed.\n");
  45.     printf("Press mouse button when done...\n");
  46.     
  47.     graphics_to_front();
  48.     background_color(RED);
  49.     erase_graphics();
  50.     old_x = RADIUS1 + CENTER_X;
  51.     old_y = CENTER_Y;
  52.     
  53.     while (!mouse_button_is_down())
  54.     {
  55.         x = cos(angle)*RADIUS1 + CENTER_X;
  56.         y = sin(angle)*RADIUS1 + CENTER_Y;
  57.         
  58.         erase_graphics();
  59.  
  60.         pen_color(WHITE);
  61.         draw_line(CENTER_X,CENTER_Y,x,y);
  62.         draw_circle(x,y,RADIUS2);
  63.         
  64.         old_x = x;
  65.         old_y = y;
  66.         get_mouse_location(&mouse_x,&mouse_y);
  67.         increment = mouse_y/10.;
  68.         angle += increment;
  69.     }
  70.     
  71.     printf("All done...\n");
  72. }
  73.         
  74.